package com.atguigu.bigdata.chapter05.transform;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.co.CoMapFunction;

/**
 * @Author lzc
 * @Date 2022/9/2 10:26
 */
public class Flink07_Connect {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 2000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(2);
    
    
        DataStreamSource<Integer> s1 = env.fromElements(1, 10, 3, 6, 9, 11);
        DataStreamSource<String> s2 = env.fromElements("a", "b", "c");
    
        s1.connect(s2)
            .map(new CoMapFunction<Integer, String, String>() {
                
                // 处理第一个流的元素
                @Override
                public String map1(Integer value) throws Exception {
                    return value + "<";
                }
                // 处理第二个流的元素
                @Override
                public String map2(String value) throws Exception {
                    return value + ">";
                }
            })
            .print();
    
    
        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
/*
connect:
1. connect一次只能连接两个流
2. 两个流的类型可以不一样
    实际使用的时候,大部分都是不一样



 */